<?php

namespace yiike\credit\models\search;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yiike\credit\models\CreditRecord;

/**
* CreditRecordSearch represents the model behind the search form about `yiike\credit\models\CreditRecord`.
*/
class CreditRecordSearch extends CreditRecord
{
/**
* @inheritdoc
*/
public function rules()
{
return [
[['id', 'user_id', 'payer_id', 'type', 'union_id', 'is_pay', 'payment_at', 'status', 'created_by', 'updated_by', 'created_at', 'updated_at'], 'integer'],
            [['sn', 'title', 'memo', 'union_from'], 'safe'],
            [['value1', 'value2', 'value3', 'blance1', 'blance2', 'blance3', 'payer_blance1', 'payer_blance2', 'payer_blance3'], 'number'],
];
}

/**
* @inheritdoc
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}

/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = CreditRecord::find();

$dataProvider = new ActiveDataProvider([
'query' => $query,
]);

$this->load($params);

if (!$this->validate()) {
// uncomment the following line if you do not want to any records when validation fails
// $query->where('0=1');
return $dataProvider;
}

$query->andFilterWhere([
            'id' => $this->id,
            'user_id' => $this->user_id,
            'payer_id' => $this->payer_id,
            'type' => $this->type,
            'value1' => $this->value1,
            'value2' => $this->value2,
            'value3' => $this->value3,
            'blance1' => $this->blance1,
            'blance2' => $this->blance2,
            'blance3' => $this->blance3,
            'payer_blance1' => $this->payer_blance1,
            'payer_blance2' => $this->payer_blance2,
            'payer_blance3' => $this->payer_blance3,
            'union_id' => $this->union_id,
            'is_pay' => $this->is_pay,
            'payment_at' => $this->payment_at,
            'status' => $this->status,
            'created_by' => $this->created_by,
            'updated_by' => $this->updated_by,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ]);

        $query->andFilterWhere(['like', 'sn', $this->sn])
            ->andFilterWhere(['like', 'title', $this->title])
            ->andFilterWhere(['like', 'memo', $this->memo])
            ->andFilterWhere(['like', 'union_from', $this->union_from]);

return $dataProvider;
}
}